package com.nl.pulsardemo.pool.config.commons.utils;


import com.nl.pulsardemo.pool.vo.ResultVO;

import javax.servlet.http.HttpSession;
import java.util.UUID;

/**
 * @author gfj
 * @date 2018/8/12 17:11
 */
public class ResultVOUtils {

    /**
     * 请求成功带返回信息
     * @param object
     * @return
     */
    public static ResultVO success(Object object){
        ResultVO resultVO =new ResultVO();
        resultVO.setRs(object);
        resultVO.setMsg("请求成功");
        resultVO.setCode(1);
        return resultVO;
    }
    /**
     * 请求成功带返回信息
     * @param msg
     * @return
     */
    public static ResultVO success(String msg){
        ResultVO resultVO =new ResultVO();
        resultVO.setMsg(msg);
        resultVO.setCode(1);
        return resultVO;
    }

    /**
     * 请求成功不带返回信息
     * @return
     */
    public static ResultVO success(){
        ResultVO resultVO =new ResultVO();
        resultVO.setMsg("请求成功");
        resultVO.setCode(1);
        return resultVO;
    }

    /**
     * 请求失败
     * @param code
     * @param msg
     * @return
     */
    public static ResultVO error(Integer code, String msg){
        ResultVO resultVO =new ResultVO();
        resultVO.setCode(code);
        resultVO.setMsg(msg);
        return resultVO;
    }
    /**
     * 请求失败返回token
     * @param code
     * @param msg
     * @param  session
     * @return
     */

    public static ResultVO error(Integer code, String msg, HttpSession session){
        ResultVO resultVO =new ResultVO();
        resultVO.setCode(code);
        resultVO.setMsg(msg);
        String token = UUID.randomUUID().toString();
        session.setAttribute("token", token);
        resultVO.setRs(token);
        return resultVO;
    }
    /**
     * 请求失败返回token
     * @param code
     * @param msg
     * @return
     */

    public static ResultVO error(Integer code, String msg, Object obj){
        ResultVO resultVO =new ResultVO();
        resultVO.setCode(code);
        resultVO.setMsg(msg);
        resultVO.setRs(obj);
        return resultVO;
    }
}
